(function (factory) {
	if (typeof define === 'function' && define.amd) {
		// AMD (Register as an anonymous module)
		define(['jquery'], factory);
	} else if (typeof exports === 'object') {
		// Node/CommonJS
		module.exports = factory(require('jquery'));
	} else {
		// Browser globals
		factory(jQuery);
	}
}(function ($) {

	var oldSwalClose = swal.close;

	swal.close = function (cb) {
		oldSwalClose();
		if (cb) {
			setTimeout(cb, 400);
		}
	}

	if (jQuery.validator) {
// 校验代码
		jQuery.validator.addMethod("validateCode", function (value, element, param) {
			return this.optional(element) || value == '' || /^[0-9a-zA-Z_\-]{1,}$/.test(value);
		}, "请输入由数字、26个英文字母或者下划线组成的字符串");

// 校验权限代码
		jQuery.validator.addMethod("validateAuthCode", function (value, element, param) {
			return this.optional(element) || value == '' || /^[A-Za-z:]*$/.test(value);
		}, "请输入由26个英文字母或者冒号组成的字符串");

//非空
		jQuery.validator.addMethod("notblank", function (value, element, param) {
			return this.optional(element) || $.trim(value).length > 0;
		});
//不能以空格开头
		jQuery.validator.addMethod("notstartblank", function (value, element, param) {
			return this.optional(element) || !(/^\s/.test(value));
		});
//不能以空格结尾
		jQuery.validator.addMethod("notendblank", function (value, element, param) {
			return this.optional(element) || !(/\s$/).test(value);
		});
//不能有空格
		jQuery.validator.addMethod("nothasblank", function (value, element, param) {
			return this.optional(element) || !(/\s/.test(value));
		});
//不能以空格开头或结尾
		jQuery.validator.addMethod("notstartorendblank", function (value, element, param) {
			return this.optional(element) || !((/^\s/.test(value)) || (/\s$/).test(value))
		});

//自动忽略前后空格，始终返回true
		jQuery.validator.addMethod("trim", function (value, element, param) {
			$(element).val($.trim(value));
			return true;
		});

//限制只能大小写字母
		jQuery.validator.addMethod("letter", function (value, element, param) {
			return this.optional(element) || /^[A-Za-z]*$/.test(value);
		});
	}
}))